<?php
namespace UploadFile;
use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\FormElementProviderInterface;

class Module implements FormElementProviderInterface
{
    public function onBootstrap(EventInterface $e)
    {
        $app = $e->getTarget();
        $eventManager = $e->getTarget()->getEventManager();
        $serviceManager = $app->getServiceManager();
        $sendListener = $serviceManager->get('role_user_create_service_factory');
        $eventManager->attach($sendListener);
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }

    public function getServiceConfig()
    {
        return array(
            'invokables' => array(
                'upload_file_service' => 'UploadFile\Service\UploadFile',
                'upload_imagine_image_service' => 'Imagine\Gd\Imagine',
            ),
            'factories' => array(
                'upload_file_module_options'            => 'UploadFile\Factory\ModuleOptionsFactory',
                'upload_file_mapper'                    => 'UploadFile\Factory\UploadFileMapperFactory',
                'upload_file_linker_mapper'                    => 'UploadFile\Factory\UploadFileLinkerMapperFactory',
                'upload_file_hydrator'                  => 'UploadFile\Factory\Mapper\UploadFileHydratorFactory',
                'upload_file_linker_hydrator'           => 'UploadFile\Factory\Mapper\UploadFileLinkerHydratorFactory',
                'upload_file_user_service_factory'      => 'UploadFile\Factory\UploadFileUserServiceFactory',
            ),
        );
    }

    public function getFormElementConfig()
    {
        return array(
            'factories' => array(
                'AlbumFieldset' => function($sm) {
                        // I assume here that the Album\Model\AlbumTable
                        // dependency have been defined too
                        $fieldset = new \UploadFile\Form\AlbumFieldset();
                        return $fieldset;
                    }
            )
        );
    }

}
